// pages/buyCar/buycar.js
const constant = require('../../constant');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    brand_list: [],
    hotcar_list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBrandList(options);
    this.getHotcarList();
  },
  //条件选车跳转
  toCondition: function (event) {
    var type = event.currentTarget.dataset.type;
    var paramstr = '';
    if (type == 'brand') {
      //商标
      var id = event.currentTarget.dataset.id;
      var title = event.currentTarget.dataset.title;
      paramstr = '?type=' + type + '&id=' + id + '&title=' + title;
    } else if (type == 'truckQyc') {
      //牵引车
      paramstr = '?type=' + type;
    } else if (type == 'truckZhc') {
      //载货车
      paramstr = '?type=' + type;
    }
    wx.navigateTo({
      url: '../findCar/findCar' + paramstr
    })
  },
  getBrandList: function (data) {
    let that = this;
    app.get('Goods/getgoodsbrand', {
      type: '1'
    }, function(res) {
        if (res.code == 200 && res.data.length > 0) {
          let list = res.data
          for (let i = 0; i < list.length; i++) {
            list[i].img = constant.config.host + list[i].img;
          }
          that.setData({
            brand_list: list,
          })
        }
      })
  },
  getHotcarList: function() {
    let that = this;
    app.get('Goods/gettruckcatlist', {
      type: '6,7',
      ishot: '1',
      page_no: '1',
      page_count: '3'
    }, function (res) {
      if (res.code == 200 && res.data.data_list.length > 0) {
        let list = res.data.data_list;
        for(var i=0; i<list.length; i++) {
          list[i].img = constant.config.host + list[i].img;
        }
        that.setData({
          hotcar_list: list,
        })
      }
    })
  },
  toCartypeDetail: function (event) {
    var item = event.currentTarget.dataset.item;
    var id = item.titlecat_id;
    var imgTitle = item.img_title;
    var price = item.price;
    if (price == '' || price == null) price = '暂无报价';
    var title = item.title;
    wx.navigateTo({
      url: '../carTypeDetail/carTypeDetail?id=' + id + '&img=' + imgTitle + '&title=' + title + '&price=' + price
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})